package com.sc.VenusQueryBeta.presenter.vip;


import com.hengjun.kingstar.sdk.utils.LogUtil;
import com.hengjun.kingstar.sdk.utils.LogUtils;
import com.sc.VenusQueryBeta.contract.vip.MsgContract;
import com.sc.VenusQueryBeta.model.bean.account.msg.MsgListBean;
import com.sc.VenusQueryBeta.model.bean.login.QueryRegisBean;
import com.sc.VenusQueryBeta.model.vip.MsgModel;

import io.reactivex.functions.Consumer;

/**
 * 推送的presenter
 * Created by Administrator on 2018/11/4.
 */

public class MsgPresenter extends MsgContract.MsgPresenter {
    @Override
    protected MsgContract.IMsgModel getModel() {
        return MsgModel.newInstance();
    }

    @Override
    public void onStart() {

    }

    public static MsgPresenter newInstance() {
        return new MsgPresenter();
    }

    @Override
    public void getMsgline(String serverAddress, String projectName, int serverPort,String sendId, String loginPort, String loginUserId) {
        if (mIView == null || mIModel == null)
            return;
        mRxManager.register(mIModel.getMsgList(serverAddress,projectName,serverPort,sendId,loginPort,loginUserId).subscribe(new Consumer<MsgListBean>() {
            @Override
            public void accept(MsgListBean msgListBean) throws Exception {
                if (mIView != null)
                    mIView.showMsgListDataSuccess(msgListBean);
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                if (mIView != null) {
                    if (mIView.isVisiable())
                        LogUtil.e("錯愕error00=="+throwable.getMessage());
                    mIView.showToast("Network error"+throwable.getMessage());
                    mIView.showNetworkError(throwable);
                }
            }
        }));
    }

    @Override
    public void queryRegisterServerSetting(String id) {
        if (mIView == null || mIModel == null)
            return;
        mRxManager.register(mIModel.queryRegisterServerSetting(id).subscribe(new Consumer<QueryRegisBean>() {
            @Override
            public void accept(QueryRegisBean queryRegisBean) throws Exception {
                if (mIView != null)
                    mIView.showQueryRegisBeanDataSuccess(queryRegisBean);
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                if (mIView != null) {
                    if (mIView.isVisiable())
                        LogUtils.e("錯愕error00=="+throwable.getMessage());
                    mIView.showToast("Network error"+throwable.getMessage());
                    mIView.showNetworkError(throwable);
                }
            }
        }));
    }
}
